﻿using Microsoft.EntityFrameworkCore;

namespace Fast.Extensions.DatabaseAccessor.EntityFrameworkCore
{
    /// <summary>
    /// 非泛型仓储
    /// </summary>
    public interface IRepository
    {
        /// <summary>
        /// 切换仓储
        /// </summary>
        /// <typeparam name="TEntity">实体类型</typeparam>
        /// <returns>仓储</returns>
        IRepository<TEntity> Change<TEntity>()
            where TEntity : class, IRootEntity, new();

        /// <summary>
        /// 切换多数据库上下文仓储
        /// </summary>
        /// <typeparam name="TEntity">实体类型</typeparam>
        /// <typeparam name="TDbContextLocator">数据库上下文定位器</typeparam>
        /// <returns>仓储</returns>
        IRepository<TEntity, TDbContextLocator> Change<TEntity, TDbContextLocator>()
            where TEntity : class, IRootEntity, new()
            where TDbContextLocator : class, IDbContextLocator;
    }
    /// <summary>
    /// 泛型仓储
    /// </summary>
    /// <typeparam name="TEntity">实体类型</typeparam>
    public interface IRepository<TEntity> : IRepository<TEntity, DefaultDbContextLocator>
        , IReadableRepository<TEntity>
        , IWritableRepository<TEntity>
        , ISqlRepository
        where TEntity : class, IRootEntity, new()
    {

    }
    /// <summary>
    /// 泛型仓储
    /// </summary>
    /// <typeparam name="TEntity">实体类型</typeparam>
    public interface IRepository<TEntity, TDbContextLocator> : IRootRepository<TEntity>
        , IRootWritableRepository<TEntity, TDbContextLocator>
        , IRootReadableRepository<TEntity, TDbContextLocator>
        , ISqlRepository<TDbContextLocator>
        where TEntity : class, IRootEntity, new()
        where TDbContextLocator : class, IDbContextLocator
    {

    }
    /// <summary>
    /// 根泛型仓储
    /// </summary>
    /// <typeparam name="TEntity">实体类型</typeparam>
    public interface IRootRepository<TEntity>
        : IRootWritableRepository<TEntity>
        , IRootReadableRepository<TEntity>
        , IRootSqlRepository
        where TEntity : class, IRootEntity, new()
    {
        /// <summary>
        /// 实体集合
        /// </summary>
        DbSet<TEntity> Entities { get; }

        /// <summary>
        /// 切换仓储
        /// </summary>
        /// <typeparam name="TChangeEntity">实体类型</typeparam>
        /// <returns>仓储</returns>
        new IRepository<TChangeEntity> Change<TChangeEntity>()
                where TChangeEntity : class, IRootEntity, new();

        /// <summary>
        /// 切换多数据库上下文仓储
        /// </summary>
        /// <typeparam name="TChangeEntity">实体类型</typeparam>
        /// <typeparam name="TChangeDbContextLocator">数据库上下文定位器</typeparam>
        /// <returns>仓储</returns>
        IRepository<TChangeEntity, TChangeDbContextLocator> Change<TChangeEntity, TChangeDbContextLocator>()
            where TChangeEntity : class, IRootEntity, new()
            where TChangeDbContextLocator : class, IDbContextLocator;
    }
}
